import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controller/CountController.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // int _count = 0;
  // 把Getx中的控制器加入共享实例
  final CountController _countController = Get.put(CountController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("首页"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text("首页"),
            const SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: () {
                      // _count--;
                      // setState(() {});
                      _countController.decrease();
                    },
                    child: const Text("减")),
                Obx(() => Text(_countController.count.toString())),
                ElevatedButton(
                    onPressed: () {
                      // _count++;
                      // setState(() {});
                      _countController.increase();
                    },
                    child: const Text("加"))
              ],
            ),
            const SizedBox(height: 20),
            ElevatedButton(
                onPressed: () {
                  // 1. 页面跳转
                  // Get.toNamed('/list');
                  // 2. 页面跳转并传参
                  Get.toNamed('/list', arguments: {"name": "张三"});
                },
                child: const Text("跳转"))
          ],
        ),
      ),
    );
  }
}
